//
//  NewsCell.m
//  KuWoCan
//
//  Created by hwd on 17/3/6.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "NewsCell.h"

@interface NewsCell()

@property (nonatomic,strong) UIImageView *imgView;

@property (nonatomic,strong) UILabel *contentLab;

@property (nonatomic,strong) UILabel *timeLab;

@end


@implementation NewsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI
{
    _imgView = [[UIImageView alloc]init];
    [_imgView sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"kuwo_logo"]];
    _imgView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:_imgView];
    _imgView.layer.cornerRadius = 3;
    _imgView.layer.masksToBounds = YES;
    [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(20 * screenW_6));
        make.top.equalTo(@(21 * screenW_6));
        make.size.mas_equalTo(CGSizeMake(95 * screenW_6, 78 * screenW_6));
    }];
    
    _contentLab = [UILabel new];
    _contentLab.textColor = [UIColor blackColor];
    _contentLab.font = KwFont(16 * screenW_6);
    _contentLab.numberOfLines = 0;
    _contentLab.text = @"类容";
    [self addSubview:_contentLab];
    [_contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_imgView.mas_right).offset(18 * screenW_6);
        make.right.equalTo(@(-20 * screenW_6));
        make.top.equalTo(_imgView.mas_top).offset(-2 * screenW_6);
        make.bottom.lessThanOrEqualTo(_imgView.mas_centerY);
    }];
    
    _timeLab = [UILabel new];
    _timeLab.textColor = [UIColor colorWithHexString:@"#777777"];
    _timeLab.font = KwFont(13 * screenW_6);
    _timeLab.text = @"2017.03.20";
    [self addSubview:_timeLab];
    [_timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.lessThanOrEqualTo(_imgView.mas_centerY).offset(10 * screenW_6);
        make.bottom.equalTo(_imgView.mas_bottom).offset(-8 * screenW_6);
        make.left.equalTo(_contentLab.mas_left);
        make.right.equalTo(_contentLab.mas_right);
    }];

    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.00];
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.bottom.equalTo(self);
        make.height.equalTo(@(5 * screenW_6));
    }];
}


- (void)setModel:(NewsListModel *)model
{
    _contentLab.text = [CommonTool flattenHTML:model.title];
//    NSLog(@"============%@",[CommonTool flattenHTML:model.content])
    [_imgView sd_setImageWithURL:[NSURL URLWithString:model.imgUrl] placeholderImage:kImg(@"kuwo_logo")];
    
    // yyyy-MM-dd HH:mm:ss   -------->    MM-dd HH:mm
    NSString *deleteYearStr = [model.createDate substringFromIndex:5];
    NSString *deleteSecStr = [deleteYearStr substringWithRange:NSMakeRange(0, deleteYearStr.length-3)];
    _timeLab.text = deleteSecStr;
}

@end
